@import org.silkframework.config.CustomTask
@import org.silkframework.workspace.Project
@import org.silkframework.runtime.plugin.PluginRegistry

@(project: Project, taskName: String, taskPlugin: Option[CustomTask])

  @widgets.pluginDialog(
    name = taskName,
    plugins = PluginRegistry.availablePlugins[CustomTask],
    currentObj = taskPlugin,
    resources = project.resources.list) {

    <script type="text/javascript">
      function savePlugin(pluginId, name, parameters) {
        // Build dataset xml
        var ctDoc = document.implementation.createDocument("", "CustomTask", null);
        var ct = ctDoc.documentElement
        ct.setAttribute('id', name);
        ct.setAttribute('type', pluginId);
        for(var i in parameters) {
          var param = ctDoc.createElement('Param');
          param.setAttribute('name', parameters[i].name);
          param.setAttribute('value', parameters[i].value);
          ct.appendChild(param);
        }
        var oSerializer = new XMLSerializer();
        var xml = oSerializer.serializeToString(ctDoc);

        // Submit task
        putTask('@config.baseUrl/workspace/projects/@project.name/customTasks/' + name, xml);
      }
    </script>
  }